<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="asserts/plugins/bootstrap/css/bootstrap.css" rel="stylesheet">
    <script src="asserts/plugins/jquery-3.6.0.min.js"></script>
    <script src="asserts/plugins/bootstrap/js/bootstrap.js"></script>
    <style>
        select{
            text-align: center;
        }
    </style>
    <script>
        /*
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String strUser_type = req.getParameter("user_type");
        String sex = req.getParameter("sex");
        String phone = req.getParameter("phone");
         */
        $(function () {
            $("#reg_btn").click(function () {
                let username = $("input[name=username]").val();
                let password = $("input[name=password]").val();
                let phone = $("input[name=phone]").val();
                let user_type = $("select[name=user_type]").val();
                let sex = '男';
                if ($("input[name=sex]")[1].checked){
                    sex = $("input[name=sex]")[1].value;
                }
                $.ajax({
                    url:"/KunKunMarket/UserController",
                    type:"get",
                    dataType:"json",
                    data:{
                        type: 'register',
                        username:username,
                        password:password,
                        phone:phone,
                        sex:sex,
                        user_type:user_type
                    },
                    success:function (respBean) {
                        alert(respBean.msg);
                        if (respBean.status == 200){
                            location.href = 'login.html';
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>
    <h1 style="text-align: center">注册</h1>
    <div class="container">
        <form>
            <div class="form-group">
                <input type="text" name="username" class="form-control " placeholder="请输入账号">
            </div>
            <div class="form-group">
                <input type="password" name="password" class="form-control " placeholder="请输入密码">
            </div>
            <div class="form-group">
                <input type="text" name="phone" class="form-control " placeholder="请输入电话">
            </div>


            <div class="form-group">
                <label for="user_type">我是：</label>
                <select class="form-control input-sm" name="user_type" id="user_type">
                    <option value="0">买家</option>
                    <option value="1">商家</option>
                </select>

            </div>
            <div class="form-group">

                <div class="checkbox">
                    性别：
                    <label>
                        男<input type="radio" name="sex" value="男" checked>
                    </label>
                    <label>
                        女<input type="radio" name="sex" value="女">
                    </label>
                </div>
            </div>


            <button type="button" id="reg_btn" class="btn btn-default">注册</button>


        </form>
    </div>

</body>
</html>